<%-- @ page language="java" contentType="text/html; charset=ISO-8859-1" --%>

<%@ page import="uk.ac.sanger.*" %>

<jsp:include  page="header.jsp"></jsp:include>

<h1>Feature list for :</h1>

<FORM METHOD="POST" ACTION="/writebackServlet/writebackServlet">
<% //get coordinate system name
   //String system_name = (String) session.getAttribute("system_name");%>
   

<div id="table">
<table >
	<tr id="row0">
	    <th>  </th>
	    <th>  </th>
		<th  ALIGN="RIGHT">FEATUREID</th>
		<th  ALIGN="RIGHT">FEATURETYPE</th>
		<th  ALIGN="RIGHT">METHOD</th>
		<th  ALIGN="RIGHT">SEGMENTID</th>
		<th  ALIGN="RIGHT">START</th>
		<th  ALIGN="RIGHT">END</th>
		<th  ALIGN="RIGHT">STRAND</th>
		<th  ALIGN="RIGHT">PHASE</th>
		<th  ALIGN="RIGHT">SCORE</th>
		<th  ALIGN="RIGHT">ATTRIBUTES</th>
	</tr>
  
     <% 
   	 	String system_name ="";
   	 	String system="";
   	
   	 	//	first check open id
		if((String)session.getAttribute("openid")==null) {
			String message = "you are not logged in, please log in first!";
			session.setAttribute("message", message);
			response.sendRedirect("login.jsp");	
		}
		 else
		{
   			String mode =(String) session.getAttribute("mode");
   			String button_text="???";
   			if (mode.equals("3")) 
   				button_text="delete";
   			if (mode.equals("2")) 
   				button_text="edit";
   			if (mode.equals("1")) {
   				session.setAttribute("mode","2");
   				button_text="edit";
   		}
   		
		// get data from db
		String system_uri = request.getParameter("uri");
		session.setAttribute("system_uri",request.getParameter("uri"));
        
		String action=request.getParameter("action");
		String group=request.getParameter("group");

		DataManager dbM = new DataManager();
		FeatureBean[] features;
		
		if (action.equals("show_group")){
  		    features = dbM.getFeaturesByGroup(group,system_uri) ; 

		}
		else{
   			
  			features = dbM.getAllFeatures(system_uri) ; 
		}
  		
  		//system name from DataManager, static variable 
  		system_name = dbM.new_system_name;
  		session.setAttribute("system_name",system_name);
  		
  		//get system id by URI
  		system=""+dbM.getIdFromUri(system_uri);
  		session.setAttribute("system",system);
  		%>	
  		
  		<h1>Coordinate system : <%=system_name%></h1>     		
  	    <% if(features!=null){
  	      for (int i=0;i<features.length;i++) { 
  		
  			if (i % 2 != 0) {
  				%>
  				<tr id="row1">
  					<%
  					} 
  			else {
  					%>
  				<tr id="row2">
  			 <%} %>
	        <td><A HREF="writebackServlet?featureid=<%=features[i].getFeatureid() %>&uri=<%=request.getParameter("uri") %>" ><%=button_text%></A>/</td>
   	        <td><A HREF="show_history.jsp?id=<%=features[i].getFeatureid() %>&uri=<%=request.getParameter("uri") %>" >history</A> </td>
            <td  ALIGN="RIGHT"><%=features[i].getFeatureid() %></td>
            <td  ALIGN="RIGHT"><%=features[i].getFeaturetype() %></td>
            <td  ALIGN="RIGHT"><%=features[i].getMethod() %></td>
            <td  ALIGN="RIGHT"><%=features[i].getSegment() %></td>
            <td  ALIGN="RIGHT"><%=features[i].getStart()%></td>
            <td  ALIGN="RIGHT"><%=features[i].getEnd() %></td>
            <td  ALIGN="RIGHT"><%=features[i].getStrand() %></td>
            <td  ALIGN="RIGHT"><%=features[i].getPhase() %></td>
            <td  ALIGN="RIGHT"><%=features[i].getScore() %></td>
            <td  ALIGN="RIGHT"><%=features[i].getNotes() %></td>
	        </tr>   	
  		  <% }}}%>
  		  
</table>
</div>

<p>
Back to   <A href="index.jsp">home</A>. 
</p>

<jsp:include  page="footer.jsp"/>